package com.fnn.mapper;

import com.fnn.entity.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface UserMapper {
    /**
     * 把user实体与user数据表中的字段映射起来
     * 查询所有用户
     * @return
     */
    @Select("select * from user")
    @Results(id="userEntity", value = {
            @Result(column = "user_id",property = "user_id"),
            @Result(column = "user_name",property = "user_name"),
            @Result(column = "user_password",property = "user_password"),
            @Result(column = "user_email",property = "user_email"),
            @Result(column = "user_role",property = "user_role"),
            @Result(column = "user_status",property = "user_status"),
            @Result(column = "session_id",property = "session_id"),
    })
    List<User> selectAll();





    /**
     * 根据邮箱查询用户
     * @param email
     * @return
     */
    @Select("select * from user where user_email=#{user_email}")
    @ResultMap(value = {"userEntity"})
    User selectByEmail(String email);






    /**
     * 根据session_id查询用户
     * @param session_id
     * @return
     */
    @Select("select * from user where session_id=#{session_id}")
    @ResultMap(value = {"userEntity"})
    User selectBySession_id(String session_id);




    /**
     * 插入用户
     * @param user
     * @return
     */
    @Insert("insert into user(user_name, user_password, user_email) values(#{user_name},#{user_password},#{user_email})")
    @ResultMap(value = {"userEntity"})
    int insertUser(User user);




    /**
     * 更新用户的session_id
     * @param user_email
     * @param session_id
     * @return
     */
    @Update("update user set session_id=#{session_id} where user_email=#{user_email}")
    @ResultMap(value = {"userEntity"})
    int insertUserSessionIdByEmail(@Param("user_email") String  user_email,@Param("session_id") String session_id);
}
